<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="auto">

      <el-form-item label="主体名称" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入主体名称"
          clearable
          size="small"
          class="w_200"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item label="注册手机号" prop="mobilePhone">
        <el-input
          v-model="queryParams.mobilePhone"
          placeholder="请输入注册手机号"
          clearable
          size="small"
          class="w_200"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item label="注册时间">
        <el-date-picker
          v-model="daterangeRegisterTime"
          size="small"
          class="w_200"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>


      <el-form-item label="是否有营业执照 " prop="businessFlag">
        <el-select v-model="queryParams.businessFlag" placeholder="请选择是否有营业执照 " clearable size="small" class="w_200">
          <el-option label="是" :value="1" />
          <el-option label="否" :value="0" />
        </el-select>
      </el-form-item>

      <!--省市区级联组件-->
      <el-form-item label="省:" prop="province">
        <el-select v-model='queryParams.province' filterable placeholder="请选择省" clearable   class="w_200">
          <el-option v-for='(temp,index) in mixinsProvinceList' :value="temp.name" :key='index' :label="temp.name"
                     @click.native='mixinsProvinceChange(temp.code)'/>
        </el-select>
      </el-form-item>


      <el-form-item label="市:" prop="city">
        <el-select v-model='queryParams.city' filterable placeholder="请选择市(请先选择省)" clearable   class="w_200">
          <el-option v-for='(temp,index) in mixinsCityList' :value="temp.name" :key='index' :label="temp.name"
                     @click.native='mixinsCityChange(temp.code)'/>
        </el-select>
      </el-form-item>


      <el-form-item label="区/县:" prop="area">
        <el-select v-model='queryParams.area' filterable placeholder="请选择区/县(请先选择市)" clearable   class="w_200">
          <el-option v-for='(temp,index) in mixinsAreaList' :value="temp.name" :key='index' :label="temp.name"  @click.native='mixinsAreaChange(temp.code)'  />
        </el-select>
      </el-form-item>
      <el-form-item label="乡镇/街道" prop="country" >
        <el-select v-model='queryParams.country' filterable placeholder="请选择乡镇/街道" clearable   class="w_200">
          <el-option v-for='(temp,index) in mixinsStreetList' :value="temp.name" :key='index' :label="temp.name"/>
        </el-select>
      </el-form-item>

      <el-form-item label="主体类型" prop="mainType">
        <el-select v-model="queryParams.mainType" placeholder="请选择主体类型" clearable size="small"     class="w_200">
          <el-option v-for="item in mainOptions"  :label="item.dictLabel" :value="item.dictValue"/>
        </el-select>
      </el-form-item>



      <el-form-item label="联系电话" prop="phoneNumber" >
        <el-input
          v-model="queryParams.phoneNumber"
          placeholder="请输入联系电话"
          clearable
          size="small"
          class="w_200"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item label="法人姓名" prop="legalPersonName" >
        <el-input
          class="w_200"
          v-model="queryParams.legalPersonName"
          placeholder="请输入法人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item >
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--<el-col :span="1.5">-->
      <!--<el-button-->
      <!--type="primary"-->
      <!--plain-->
      <!--icon="el-icon-plus"-->
      <!--size="mini"-->
      <!--@click="handleAdd"-->
      <!--v-hasPermi="['nongjt:perfect:add']"-->
      <!--&gt;新增</el-button>-->
      <!--</el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['nongjt:perfect:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['nongjt:perfect:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['nongjt:perfect:export']"
        >导出</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          icon="el-icon-refresh"-->
<!--          size="mini"-->
<!--          @click="handleResetPassword"-->
<!--          v-hasPermi="['nongjt:perfect:edit']"-->
<!--        >重置密码</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="perfectList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="注册手机号" align="center" prop="mobilePhone"  width="120"/>
      <el-table-column label="是否有营业执照" align="center" prop="businessFlag" width="100">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.businessFlag === 1" type="success">是</el-tag>
          <el-tag v-else type="danger">否</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="主体名称" align="center" prop="companyName" width="180" />
      <el-table-column label="法人名称" align="center" prop="legalPersonName" />
      <el-table-column label="统一社会信用代码" align="center" prop="creditCode" width="140"/>
      <el-table-column label="证件号码" align="center" prop="idNumber" width="170" />
      <el-table-column label="注册资金（万元）" align="center" prop="registerMoney" width="130" />
      <el-table-column label="企业成立时间" align="center" prop="foundTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.foundTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="注册时间" align="center" prop="registerTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.registerTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="联系电话" align="center" prop="phoneNumber" width="120"/>
      <el-table-column label="详细地址" align="center">
        <el-table-column label="省" align="center" prop="province" />
        <el-table-column label="市" align="center" prop="city" />
        <el-table-column label="区/县" align="center" prop="area" />
        <el-table-column label="乡镇/街道" align="center" prop="country" width="140" />
        <el-table-column label="详细地址" align="center" prop="detailAddress" width="180"/>
      </el-table-column>
      <el-table-column label="所属行业" align="center" prop="industryType" >
        <template slot-scope="scope">
          <dict-tag :options="industryOptions" :value="scope.row.industryType"/>
        </template>
      </el-table-column>
      <el-table-column label="主体类型" align="center" prop="mainType"  width="170">
        <template slot-scope="scope">
          <dict-tag :options="mainOptions" :value="scope.row.mainType"/>
        </template>
      </el-table-column>
      <el-table-column label="生产类型" align="center" prop="produceType" width="120" >
        <template slot-scope="scope">
          <dict-tag :options="produceOptions" :value="scope.row.produceType"/>
        </template>
      </el-table-column>
      <el-table-column label="营业执照" align="center" prop="businessLicenseUrl" >
        <template slot-scope="scope">
          <div v-if="scope.row.businessLicenseUrl">
            <el-popover
              placement="right"
              width="200"
              trigger="hover">
              <el-image :src="getView(scope.row.businessLicenseUrl)" class="imgStyle"/>
              <el-image slot="reference" :src="getView(scope.row.businessLicenseUrl)" style="max-height: 50px;max-width: 150px"/>
            </el-popover>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="认证资质" align="center" prop="certificationQualificationUrl" >
        <template slot-scope="scope">
          <div v-if="scope.row.certificationQualificationUrl">
            <el-popover
              placement="right"
              width="200"
              trigger="hover">
              <el-image :src="getView(scope.row.certificationQualificationUrl)" class="imgStyle"/>
              <el-image slot="reference" :src="getView(scope.row.certificationQualificationUrl)" style="max-height: 50px;max-width: 150px"/>
            </el-popover>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="品牌logo" align="center" prop="logoUrl" >
        <template slot-scope="scope">
          <div v-if="scope.row.logoUrl">
            <el-popover
              placement="right"
              width="200"
              trigger="hover">
              <el-image :src="getView(scope.row.logoUrl)" class="imgStyle"/>
              <el-image slot="reference" :src="getView(scope.row.logoUrl)" style="max-height: 50px;max-width: 150px"/>
            </el-popover>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="照片墙" align="center" prop="photoWall" >
        <template slot-scope="scope">
          <div v-if="scope.row.photoWall">
            <el-popover
              placement="right"
              width="200"
              trigger="hover">
              <el-image :src="getView(scope.row.photoWall)" class="imgStyle"/>
              <el-image slot="reference" :src="getView(scope.row.photoWall)" style="max-height: 50px;max-width: 150px"/>
            </el-popover>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="审核状态" align="center" prop="examineStatus" >
        <template  slot-scope="scope">
          <el-tag v-if="scope.row.examineStatus===2" type="success">已通过</el-tag>
          <el-tag v-if="scope.row.examineStatus===1" type="danger">不通过</el-tag>
          <el-tag v-if="scope.row.examineStatus===0" type="warning">待审核</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="审核时间" align="center" prop="examineTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.examineTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否打印合格证抬头" align="center" prop="certificateTitleFlag" width="140" >
        <template  slot-scope="scope">
          <el-tag v-if="scope.row.certificateTitleFlag===1" type="success">已打印</el-tag>
          <el-tag v-if="scope.row.certificateTitleFlag===0" type="danger">未打印</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" align="center" width="180">
        <template slot-scope="scope">
          <el-dropdown-item>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['nongjt:perfect:edit']"
            >编辑</el-button>
          </el-dropdown-item>
          <el-dropdown>
            <span class="el-dropdown-link">
              更多<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleExamine(scope.row)"
                  v-hasPermi="['nongjt:perfect:edit']"
                >审核</el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-refresh"
                  @click="handleResetPassword(scope.row)"
                  v-hasPermi="['nongjt:perfect:edit']"
                >重置</el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDelete(scope.row)"
                  v-hasPermi="['nongjt:perfect:remove']"
                >删除</el-button>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改用户完善信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="auto">
        <el-form-item label="注册手机号" prop="mobilePhone">
          <el-input v-model="form.mobilePhone" placeholder="请输入注册手机号" disabled />
        </el-form-item>
        <el-form-item label="注册时间" prop="registerTime">
          <el-date-picker clearable size="small"
                          v-model="form.registerTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择注册时间"
                          disabled>
          </el-date-picker>
        </el-form-item>
        <el-form-item label="主体名称" prop="companyName">
          <el-input v-model="form.companyName" placeholder="请输入主体名称" />
        </el-form-item>
        <el-form-item label="法人姓名" prop="legalPersonName">
          <el-input v-model="form.legalPersonName" placeholder="请输入法人姓名" />
        </el-form-item>
        <el-form-item label="证件号码" prop="idNumber">
          <el-input v-model="form.idNumber" placeholder="请输入证件号码" />
        </el-form-item>
        <el-form-item label="联系电话" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="省" prop="province">
          <el-select v-model='form.province' filterable placeholder="请选择省" >
            <el-option v-for='(temp,index) in mixinsProvinceList' :value="temp.name" :key='index' :label="temp.name"
                       @click.native='mixinsProvinceChange(temp.code)'/>
          </el-select>
        </el-form-item>
        <el-form-item label="市" prop="city">
          <el-select v-model='form.city' filterable placeholder="请选择市(请先选择省)" >
            <el-option v-for='(temp,index) in mixinsCityList' :value="temp.name" :key='index' :label="temp.name"
                       @click.native='mixinsCityChange(temp.code)'/>
          </el-select>
        </el-form-item>
        <el-form-item label="区/县" prop="area">
          <el-select v-model='form.area' filterable placeholder="请选择区/县(请先选择市)" >
            <el-option v-for='(temp,index) in mixinsAreaList' :value="temp.name" :key='index' :label="temp.name" @click.native='mixinsAreaChange(temp.code)' />
          </el-select>
        </el-form-item>
        <el-form-item label="乡镇/街道" prop="country">
          <el-select v-model='form.country' filterable placeholder="请选择乡镇/街道(请先选择区/县)" >
            <el-option v-for='(temp,index) in mixinsStreetList' :value="temp.name" :key='index' :label="temp.name" @click.native='streetChange(temp.code)' />
          </el-select>
        </el-form-item>
        <el-form-item label="详细地址" prop="detailAddress">
          <el-input v-model="form.detailAddress" placeholder="请输入详细地址" />
        </el-form-item>
        <el-form-item label="地址编码" prop="addressCode">
          <el-input v-model="form.addressCode" placeholder="请输入地址编码" disabled />
        </el-form-item>
        <el-form-item label="生产类型" prop="produceType">
          <el-select v-model="form.produceType" placeholder="请选择生产类型">
            <el-option v-for="item in produceOptions"  :label="item.dictLabel" :value="item.dictValue"/>
          </el-select>
        </el-form-item>
        <el-form-item label="所属行业" prop="industryType">
          <el-select v-model="form.industryType" placeholder="请选择行业类型">
            <el-option v-for="item in industryOptions"  :label="item.dictLabel" :value="item.dictValue"/>
          </el-select>
        </el-form-item>
        <el-form-item label="主体类型" prop="mainType">
          <el-select v-model="form.mainType" placeholder="请选择主体类型">
            <el-option v-for="item in mainOptions"  :label="item.dictLabel" :value="item.dictValue"/>
          </el-select>
        </el-form-item>
        <el-form-item label="统一社会信用代码" prop="creditCode">
          <el-input v-model="form.creditCode" placeholder="请输入统一社会信用代码" />
        </el-form-item>
        <el-form-item label="企业成立时间" prop="foundTime">
          <el-date-picker clearable size="small"
                          v-model="form.foundTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择企业成立时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="注册资金(万元)" prop="registerMoney">
          <el-input v-model="form.registerMoney" placeholder="请输入注册资金" />
        </el-form-item>
        <el-form-item label="是否有营业执照 " prop="businessFlag">
          <el-radio-group v-model="form.businessFlag">
            <el-radio-button :label="1">是</el-radio-button>
            <el-radio-button :label="0">否</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="营业执照" prop="businessLicenseUrl">
          <imageUpload v-model="form.businessLicenseUrl"/>
        </el-form-item>
        <el-form-item label="认证资质">
          <imageUpload v-model="form.certificationQualificationUrl"/>
        </el-form-item>
        <el-form-item label="品牌logo" prop="logoUrl">
          <imageUpload v-model="form.logoUrl"/>
        </el-form-item>
        <el-form-item label="照片墙">
          <imageUpload v-model="form.photoWall"/>
        </el-form-item>
        <el-form-item label="照片墙介绍" prop="photoMsg">
          <el-input v-model="form.photoMsg" placeholder="请输入照片墙介绍" type="textarea"/>
        </el-form-item>

        <el-form-item label="是否同步到成都市" prop="isSync">
          <el-radio-group v-model="form.isSync">
            <el-radio-button :label="1">是</el-radio-button>
            <el-radio-button :label="0">否</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否有省平台权限" prop="sptAuth">
          <el-radio-group v-model="form.sptAuth">
            <el-radio-button :label="1">是</el-radio-button>
            <el-radio-button :label="0">否</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否打印合格证抬头" prop="certificateTitleFlag">
          <el-radio-group v-model="form.certificateTitleFlag">
            <el-radio-button :label="1">是</el-radio-button>
            <el-radio-button :label="0">否</el-radio-button>
          </el-radio-group>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 审核用户完善信息对话框 -->
    <el-dialog title="审核完善信息" :visible.sync="openExamine" width="700px" append-to-body>
      <el-form ref="form2" :model="form2" :rules="rules2" label-width="auto">
        <el-form-item label="是否通过" prop="examineStatus">
          <el-radio-group v-model="form2.examineStatus">
            <el-radio-button :label="2">通过</el-radio-button>
            <el-radio-button :label="1">不通过</el-radio-button>
            <el-radio-button :label="0">待审核</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="examineMsg" >
          <el-input
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 4}"
            v-model="form2.examineMsg">
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="examineSubmit">确 定</el-button>
        <el-button @click="examineCancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 重置密码对话框 -->
    <el-dialog title="重置密码" :visible.sync="resetPasswordDialog" width="500px" append-to-body>
      <el-form ref="resetPasswordForm" :model="resetPasswordForm" :rules="resetPasswordRules" label-width="auto">
        <el-form-item label="账号" prop="account">
          <el-input v-model="resetPasswordForm.account" placeholder="请输入账号" disabled />
        </el-form-item>
        <el-form-item label="新密码" prop="newPassword">
          <el-input v-model="resetPasswordForm.newPassword" type="password" :show-password="true" placeholder="请输入新密码" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitResetPassword">确 定</el-button>
        <el-button @click="resetPasswordDialog = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listUser_perfect, getUser_perfect, delUser_perfect, addUser_perfect, updateUser_perfect, exportUser_perfect, auditUser_perfect, resetPassword } from "@/api/certificate/user_perfect";
import {getFileAccessHttpUrl} from "../../../api/manage";
import {AreaMixins} from "../../../mixins/AreaMixins";
import {getUser, resetUserPwd} from "@/api/system/user";

export default {
  name: "NjtUserPerfectList",
  mixins:[AreaMixins],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户完善信息表格数据
      perfectList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openExamine: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mobilePhone: null,
        registerTime: null,
        companyName: null,
        legalPersonName: null,
        businessFlag: null,
        businessLicenseUrl: null,
        certificationQualificationUrl: null,
        province: null,
        city: null,
        area: null,
        country: null,
        detailAddress: null,
        produceType: null,
        mainType: null,
        industryType: null,
        phoneNumber: null,
        creditCode: null,
        idNumber: null,
        registerMoney: null,
        logoUrl: null,
        photoWall: null,
        photoMsg: null,
        longitude: null,
        latitude: null,
        foundTime: null,
        examineStatus: null,
        examineMsg: null,
        examineTime: null,
        sptPassword: null,
        sptLoginName: null,
        sptAuth: null,
        isSync: null,
        certificateTitleFlag: null,
        signUrl: null,
      },
      // 表单参数
      form: {},
      form2: {
        examineStatus:2
      },
      // 表单校验
      rules: {
        mobilePhone: [
          { required: true, message: "注册手机号不能为空", trigger: "blur" }
        ],
        registerTime: [
          { required: true, message: "注册时间不能为空", trigger: "blur" }
        ],
        companyName: [
          { required: true, message: "主体名称不能为空", trigger: "blur" }
        ],
        legalPersonName: [
          { required: true, message: "法人姓名不能为空", trigger: "blur" }
        ],
        phoneNumber: [
          { required: true, message: "联系电话不能为空", trigger: "blur" }
        ],
        province: [
          { required: true, message: "省不能为空", trigger: "blur" }
        ],
        city: [
          { required: true, message: "市不能为空", trigger: "blur" }
        ],
        area: [
          { required: true, message: "区/县不能为空", trigger: "blur" }
        ],
        country: [
          { required: true, message: "乡镇/街道不能为空", trigger: "blur" }
        ],
        detailAddress: [
          { required: true, message: "详细地址不能为空", trigger: "blur" }
        ],
        addressCode: [
          { required: true, message: "地址编码不能为空", trigger: "blur" }
        ],
        produceType: [
          { required: true, message: "生产类型不能为空", trigger: "blur" }
        ],
        industryType: [
          { required: true, message: "所属行业不能为空", trigger: "blur" }
        ],
        mainType: [
          { required: true, message: "主体类型不能为空", trigger: "blur" }
        ],
        creditCode: [
          { required: true, message: "统一社会信用代码不能为空", trigger: "blur" }
        ],
        foundTime: [
          { required: true, message: "企业成立时间不能为空", trigger: "blur" }
        ],
        registerMoney: [
          { required: true, message: "注册资金(万元)不能为空", trigger: "blur" }
        ],
        businessFlag: [
          { required: true, message: "请选择是否有营业执照", trigger: "blur" }
        ],
        businessLicenseUrl: [
          { required: true, message: "营业执照不能为空", trigger: "blur" }
        ],
      },
      rules2: {

      },
      //行业类型
      industryOptions:[],
      //主体类型
      mainOptions:[],
      //生产类型
      produceOptions:[],
      daterangeRegisterTime:[],
      resetPasswordDialog: false,
      resetPasswordForm: {
        account: '',
        newPassword: '',
        userId: ''
      },
      resetPasswordRules: {
        newPassword: [
          { required: true, message: "新密码不能为空", trigger: "blur" }
        ]
      },
    };
  },
  created() {
    this.getList();
    //行业类型
    this.getDicts("industry_type").then(response => {
      this.industryOptions = response.data;
    });
    this.getDicts("main_type").then(response => {
      this.mainOptions = response.data;
    });
    this.getDicts("produce_type").then(response => {
      this.produceOptions = response.data;
    });
    this.init()
  },
  methods: {
    init() {
      let country = this.$route.query.country
      if (country) {
        // 如果路由里有查询参数，则设置默认查询条件
        this.queryParams.country = country
      }
    },
    /** 查询用户完善信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeRegisterTime && '' != this.daterangeRegisterTime) {
        this.queryParams.params["beginRegisterTime"] = this.daterangeRegisterTime[0];
        this.queryParams.params["endRegisterTime"] = this.daterangeRegisterTime[1];
      }
      listUser_perfect(this.queryParams).then(response => {
        this.perfectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮
    examineCancel() {
      this.openExamine = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        mobilePhone: null,
        registerTime: null,
        companyName: null,
        legalPersonName: null,
        businessFlag: 0,
        businessLicenseUrl: null,
        certificationQualificationUrl: null,
        province: null,
        city: null,
        area: null,
        country: null,
        detailAddress: null,
        addressCode: null,
        produceType: null,
        mainType: null,
        industryType: null,
        phoneNumber: null,
        creditCode: null,
        idNumber: null,
        registerMoney: null,
        logoUrl: null,
        photoWall: null,
        photoMsg: null,
        longitude: null,
        latitude: null,
        foundTime: null,
        examineStatus: 0,
        examineMsg: null,
        examineTime: null,
        sptPassword: null,
        sptLoginName: null,
        sptAuth: null,
        isSync: null,
        certificateTitleFlag: null,
        signUrl: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
      this.resetForm("queryForm");
      this.mixinsResetAreaList();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeRegisterTime = [];
      this.resetForm("queryForm");
      this.mixinsResetAreaList();
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户完善信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getUser_perfect(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改用户完善信息";

      });
    },
    /** 审核按钮操作 */
    handleExamine(row) {
      this.form2={
        examineStatus: 0,
        examineMsg: null
      }
      const id = row.id
      getUser_perfect(id).then(response => {
        this.form2 = response.data;
        this.openExamine = true;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateUser_perfect(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addUser_perfect(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 审核提交按钮 */
    examineSubmit() {
      this.$refs["form2"].validate(valid => {

        console.log('valid',valid)
        if (valid) {
          // this.form2.examineTime=new Date();
          updateUser_perfect(this.form2).then(response => {
            this.$modal.msgSuccess("审核成功");
            this.openExamine = false;
            this.getList();
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除用户完善信息编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return delUser_perfect(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有用户完善信息数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.exportLoading = true;
        return exportUser_perfect(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    },
    getView(url){
      return getFileAccessHttpUrl(url);
    },

    handleResetPassword(row) {
      // 假设当前用户信息存储在 row 中
      // 使用 row.id 获取用户信息
      getUser(row.id).then(response => {
        // 检查 response.data 是否为 null 或 undefined
        if (response.data) {
          console.log("获取用户信息成功:", response.data)
          // 这里假设 response.data 包含 username 字段
          this.resetPasswordForm.account = response.data.userName;
          // this.resetPasswordForm.newPassword = response.data.password;
          this.resetPasswordForm.userId = response.data.userId;
          // 打开重置密码对话框
          this.resetPasswordDialog = true;
        } else {
          this.$modal.msgError("获取用户信息失败");
        }
      }).catch(error => {
        console.error("获取用户信息时发生错误:", error);
        this.$modal.msgError("获取用户信息失败");
      });
    },
    submitResetPassword() {
      this.$refs["resetPasswordForm"].validate(valid => {
        if (valid) {
          // 调用重置密码的API
          resetUserPwd(this.resetPasswordForm.userId, this.resetPasswordForm.newPassword).then(response => {
            this.$modal.msgSuccess("重置密码成功");
            this.resetPasswordDialog = false;
          });
        }
      });
    },
    //选择街道改变
    streetChange(code) {
      // 回显地址编码
      this.form.addressCode=code
    },
  }
};
</script>
<style lang="scss" scoped>
.w_200{
  width: 200px;
}
</style>
